/***
* Feel free to use this code however you wish.
* Created by Alie Tan (www(dot)alietan(dot)com)
*/

#include <mastdlib.h>

#include "XPoint.h"

XPoint::XPoint(double x, double y, double z)
{
	this->x = x;
	this->y = y;
	this->z = z;
}

XPoint::XPoint(XPoint *point)
{
	this->x = point->GetX();
	this->y = point->GetY();
	this->z = point->GetZ();
}

XPoint::XPoint()
{
}

double XPoint::GetX()
{
	return x;
}

double XPoint::GetY()
{
	return y;
}

double XPoint::GetZ()
{
	return z;
}

void XPoint::SetX(double x)
{
	this->x = x;
}

void XPoint::SetY(double y)
{
	this->y = y;
}

void XPoint::SetZ(double z)
{
	this->z = z;
}

void XPoint::MoveBy(XPoint *point)
{
	this->x += point->GetX();
	this->y += point->GetY();
	this->z += point->GetZ();
}

void XPoint::MoveBy(double x, double y, double z) 
{
	this->x += x;
	this->y += y;
	this->z += z;
}

void XPoint::Negate()
{
	this->x *= -1;
	this->y *= -1;
	this->z *= -1;
}

double degreeToRadian(double degree) {
	double radian = 0;
	radian = degree * (PI/180);
	return radian;
}

void XPoint::Rotate(XPoint *rotationOrigin, double angle, int axis)
{
	switch(axis)
	{
		case X_AXIS:
		{			
			break;
		}
		case Y_AXIS:
		{
			break;
		}
		case Z_AXIS:
		{
			rotationOrigin->Negate();
			MoveBy(rotationOrigin);
			
			double newX = (x * cos(degreeToRadian(angle))) -
						  (y * sin(degreeToRadian(angle)));
			double newY = (x * sin(degreeToRadian(angle))) +
						  (y * cos(degreeToRadian(angle)));
			
			x = newX;
			y = newY;
			
			rotationOrigin->Negate();
			MoveBy(rotationOrigin);
			
			break;
		}
		default:
		{
			break;
		}
	}
}

void XPoint::Scale(XPoint *scaleOrigin, double scaleFactor) 
{
	scaleOrigin->Negate();
	MoveBy(scaleOrigin);
	
	x *= scaleFactor;
	y *= scaleFactor;
	z *= scaleFactor;

	scaleOrigin->Negate();
	MoveBy(scaleOrigin);
}

void XPoint::Shear(double angle) 
{
}

void XPoint::Stretch(XPoint *from, XPoint *to) 
{
}

bool XPoint::LessThan(XPoint *point)
{
//	printf("LessThan:%s\n", this->Print());
//	printf("LessThan:%s\n", point->Print());
	return this->x < point->x &&
		   this->y < point->y &&
		   this->z < point->z;
}

bool XPoint::GreaterThan(XPoint *point)
{
	return this->x > point->x &&
		   this->y > point->y &&
		   this->z > point->z;
}

bool XPoint::LessThanEqual(XPoint *point)
{
	return this->x <= point->x &&
		   this->y <= point->y &&
		   this->z <= point->z;
}

bool XPoint::GreaterThanEqual(XPoint *point)
{
	return this->x >= point->x &&
		   this->y >= point->y &&
		   this->z >= point->z;
}

bool XPoint::Equal(XPoint *point)
{
	return this->x == point->x &&
		   this->y == point->y &&
		   this->z == point->z;
}


